package Tutorial1;

/**
 * Created with IntelliJ IDEA.
 * User: Bjarke
 * Date: 13-10-13
 * Time: 22:42
 * To change this template use File | Settings | File Templates.
 */
public class WorkWithAnimals {
    public static void main(String[] args){

        Dog fido = new Dog();
        fido.setName("Fido");
        System.out.println(fido.getName());

        fido.digHole();

        fido.setWeight(-1);

        int randNum = 10;

        // This doesn't change the value of the variable.
        fido.changeVar(randNum);
        System.out.println("randNum after the method call: "+ randNum);

        // This changes the value of the variable.
        changeObjectName(fido);
        System.out.println("Dogname after method call changeObjectName: " + fido.getName());

        /**
         * Start from tutorial 2 on polymorphism here
         */
        Animal doggy = new Dog();
        Animal kitty = new Cat();

        System.out.println("Doggy says: " + doggy.getSound());
        System.out.println("Kitty says: " + kitty.getSound());

        Animal[] animals = new Animal[4];
        animals[0] = doggy;
        animals[1] = kitty;

        System.out.println("Doggy says: " + animals[0].getSound());
        System.out.println("Kitty says: " + animals[1].getSound());

        speakAnimal(doggy);
        ((Dog)doggy).digHole();

        Giraffe giraffe = new Giraffe();
        giraffe.setName("Frank");
        System.out.println(giraffe.getName());

    }

    public static void changeObjectName(Dog fido){
        fido.setName("'Marcus'");

    }

    public static void speakAnimal(Animal randAnimal){
        System.out.println("Animal says: " + randAnimal.getSound());
    }

    public void sayHello(){
        System.out.println("Hello");
    }
}
